package servlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import entity.Group;
import entity.User;
import serviceImpl.GainTeam;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "FreshGroupServlet", value = "/FreshGroupServlet")
public class FreshGroupServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        request.setCharacterEncoding("UTF-8");

        PrintWriter out =response.getWriter();

        User user =(User) request.getSession().getAttribute("user");
        user.setLevel("5");
    //    System.out.println("FreshGroupServlet:"+user);
        GainTeam gain=new GainTeam();
        Group group = gain.GainTeam(user);
      //  System.out.println(group);


        ObjectMapper mapper = new ObjectMapper(); //Jackson的核心类
        String json = mapper.writeValueAsString(group);

      //     System.out.println(json.toString());
        out.print(json);
    }
}
